<style>
    .layui-table-cell .layui-table-sort {
        display: none;
    }
</style>

<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <div class="layui-form lay-header">
                <div class="toolbar">
                    <div class="layui-form-item lay-query-content">
                        <div class="lay-query-box">
                            <div class="query-lt">
                                <div class="layui-inline">
                                    <label class="layui-form-label">所属工序：</label>
                                    <div class="layui-input-inline">
                                        <input name="processCode" id="processCode" class="layui-input"
                                               type="text"
                                               placeholder="所属工序" autocomplete="off"/>
                                    </div>
                                </div>
                                <!-- 客户名称 -->
                                <div class="layui-inline">
                                    <label class="layui-form-label">开工单编号：</label>
                                    <div class="layui-input-inline">
                                        <input name="workOrderCode" id="workOrderCode" class="layui-input"
                                               type="text"
                                               placeholder="请输入任务编号" autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">质检任务编号：</label>
                                    <div class="layui-input-inline">
                                        <input name="code" id="code" class="layui-input"
                                               type="text"
                                               placeholder="请输入任务编号" autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">送检人：</label>
                                    <div class="layui-input-inline">
                                        <select id='sjPersion' lay-search="" name="sjPersion"
                                                lay-filter="sjPersion"
                                                class="common-select-search">
                                            <option value="">请选择</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">检验员：</label>
                                    <div class="layui-input-inline">
                                        <select id='jcPersion' lay-search="" name="jcPersion"
                                                lay-filter="jcPersion"
                                                class="common-select-search">
                                            <option value="">请选择</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">状态：</label>
                                    <div class="layui-input-inline">
                                        <select id='status' name="status"
                                                lay-filter="status"
                                                class="common-select-search">
                                            <option value="">请选择</option>
                                            <option value="1">送检中</option>
                                            <option value="2">待检验</option>
                                            <option value="3">完成</option>
                                            <option value="4">关闭</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="query-rt">
                                <div class="layui-inline">
                                    <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog"
                                            lay-submit layui-form-keyDownSearch="true">查询
                                    </button>
                                    <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>
                                        重置
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="lay-btn-rows">
                        <div class="lay-btn-box">
                            <div class="lay-btn-lt">
                                <button id="productQualityAdd" type="button" class="layui-btn icon-btn color-reseda">
                                    添加质检任务
                                </button>
<!--                                <button id="productPlanningZYAdd" type="button" class="layui-btn icon-btn color-reseda">-->
<!--                                    添加自研任务-->
<!--                                </button>-->
                            </div>
                            <div class="lay-btn-rt">

                            </div>
                        </div>
                    </div>
                </div>
                <!-- 表格 -->
                <div class="table-bor">
                    <table class="layui-table" id="proQualityTaskTableInfo"
                           lay-filter="proQualityTaskTableInfo"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="proQualityTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">详情</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="closeAndEnd">关闭</a>
<!--    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="print">打印</a>-->
</script>

<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'laydate', 'admin', 'laytpl', 'tableTreeDj', 'config'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var table = layui.table;
        var form = layui.form;
        var config = layui.config;
        var admin = layui.admin;


        //初始化送检人
        admin.req('user/admin/user/getAll', {workOrderId: 9999}, function (res) {
            if (res.code == 200) {
                if (res.data.length > 0) {
                    $.each(res.data, function (index, item) {
                        $("#sjPersion").append(new Option(item.nickname, item.id));
                    })
                    form.render('select');
                }
            } else {
                layer.msg(res.msg, {icon: 2});
            }
        }, 'GET');

        //初始化检测人
        admin.req('user/admin/user/getAll', {workOrderId: 9999}, function (res) {
            if (res.code == 200) {
                if (res.data.length > 0) {
                    $.each(res.data, function (index, item) {
                        $("#jcPersion").append(new Option(item.nickname, item.id));
                    })
                    form.render('select');
                }
            } else {
                layer.msg(res.msg, {icon: 2});
            }
        }, 'GET');


        // 渲染表格
        var insTb = table.render({
            id: 'proQualityTaskTableInfo',
            elem: '#proQualityTaskTableInfo',
            url: config.base + 'production/quality/admin/firstTask/list',
            page: true,
            toolbar: true,
            defaultToolbar: ["filter"],
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers', title: '序号', fixed: 'center'}
                , {field: 'code', title: '质检任务单编码', fixed: 'center'}
                , {field: 'typeName', title: '质检分类', fixed: 'center'}
                , {field: 'classifyName', title: '质检类型', fixed: 'center'}
                , {field: 'workOrderCode', title: '所属开工单', fixed: 'center'}
                , {field: 'sjWorkstation', title: '送检工站', fixed: 'center'}
                , {field: 'skuCode', fixed: 'center', title: '产品编码'}
                , {field: 'statusName', title: '状态', fixed: 'center'}
                , {field: 'sjPerson', title: '送检人', fixed: 'center'}
                , {field: 'sjTime', title: '送检时间', fixed: 'center'}
                , {field: 'quantity', title: '送检数量', fixed: 'center'}
                , {align: 'center', toolbar: '#proQualityTableBar', title: '操作', width: 250}
            ]],
            done: function (res, curr, count) {
                //移除按钮
                var menuButton = config.getMenuButton(location.hash);
                console.log("menuButtton", menuButton);
                if (menuButton.indexOf("搜索") == -1) {
                    $('.layui-form.toolbar').remove();
                }
                if (menuButton.indexOf("修改") == -1) {
                    $("[lay-event='edit']").remove();
                }
                if (menuButton.indexOf("删除") == -1) {
                    $("[lay-event='del']").remove();
                }
            }
        });

        //渲染下拉
        form.render('select');

        // 工具条点击事件
        table.on('tool(proQualityTaskTableInfo)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') { //修改
                productQualityAdd(data);
            } else if (obj.event === 'detail') { //详情
                showDetailModel(data);
            } else if (obj.event === 'closeAndEnd') { //关闭
                closeAndEnd(data);
            } else if (obj.event === 'print') { //产品规划
                console.log("打印...");
            }
        });

        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            data.field.givenStartTimed = $("#givenStartTimed").val();
            insTb.reload({where: data.field, page: {curr: 1}}, 'data');
        });

        // 重置搜索
        form.on('submit(resets)', data => {
            $(".lay-header").find('select').val("");
            $(".lay-header").find('input').val("");
            let field = data.field;
            for (let key in field) {
                field[key] = ''
            }
            insTb.reload({where: field, page: {curr: 1}}, 'data');
        });

        // 添加按钮点击事件
        $('#productQualityAdd').click(function () {
            productQualityAdd();
        });

        //关闭
        function closeAndEnd(data){
            layer.confirm('确认要关闭该任务吗？', {
                offset: '65px',
                skin: 'layui-layer-admin'
            }, function (i) {
                admin.req('production/quality/admin/firstTask/'+data.id,{}, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        table.reload(insTb, {});
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'DELETE');
            });
        }

        //详情
        function showDetailModel(data){
            admin.putTempData("qualityTaskDetailData",data);
            admin.formOpen({
                type: 1,
                area: ['1380px', '70%'],
                offset: ['73px', '345px'],
                style: 'font-size: 20px;',
                title: "质检任务详情",
                path: "components/product/qualityTask/taskQualityDetail.html",
                finish: function () {
                    table.reload(insTb, {});
                }
            });
        }

        // 添加质检任务
        function productQualityAdd(data) {
            let title;
            let path;
            if (data){
                title = "修改质检任务";
                admin.putTempData("qualityTaskData",data);
                path = "components/product/qualityTask/taskQualityUpdate.html"
            }else {
                title = "添加质检任务";
                path = "components/product/qualityTask/taskQualityAdd.html"
            }
            admin.formOpen({
                type: 1,
                area: ['1380px', '70%'],
                offset: ['73px', '345px'],
                style: 'font-size: 20px;',
                title: title,
                path: path,
                finish: function () {
                    table.reload(insTb, {});
                }
            });
        }
    });
</script>